﻿using System.Diagnostics;
using System.IO;

namespace TroubleshootingofBeanBagAssistant.lCheck
{
	public class FirewallCheck : IDiagnosticCheck
	{
		public string Name => "防火墙规则检查";
		public CheckResult Run()
		{
			try
			{
				string exePath = @"C:\Users\Administrator\AppData\Local\Programs\BeanBagAIBrowserEdge\Applications\AIMouse.exe";
				var psi = new ProcessStartInfo
				{
					FileName = "netsh",
					Arguments = $"advfirewall firewall show rule name=all | find /I \"{Path.GetFileName(exePath)}\"",
					RedirectStandardOutput = true,
					UseShellExecute = false,
					CreateNoWindow = true
				};
				using var process = Process.Start(psi);
				string output = process.StandardOutput.ReadToEnd();
				process.WaitForExit();

				if (!string.IsNullOrWhiteSpace(output))
					return new CheckResult { Title = "检测到防火墙规则可能限制软件使用", Detail = $"相关规则: {output.Trim()}" };
				else
					return new CheckResult { Title = "未检测到防火墙限制本软件的规则", Detail = "防火墙未发现限制规则" };
			}
			catch (Exception ex)
			{
				return new CheckResult { Title = "防火墙规则检查异常", Detail = ex.Message };
			}
		}
	}
}
